package com.tt.controller;

import com.tt.common.Const.TtConstans;
import com.tt.common.page.TtResult;
import com.tt.common.param.FtpPo;
import com.tt.common.util.JSONUtil;
import com.tt.service.IFileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author 青青
 */
@Controller
@RequestMapping("/upload")
public class FileUploadController
{

    @Value("${FTPHost}")
    private String Image_Base_Url;

    @Value("${FTPPASSRD}")
    private String FTPPASSRD ;

    @Value("${FTP_USERNAME}")
    private String FTP_USERNAME;

    @Value("${FTP_PORT}")
    private Integer FTP_PORT;

    @Value("${IMAGE_BASE_HOME}")
    private String IMAGE_BASE_home;

    @Value("${FTPHost}")
    private String FTPHost;

    @Autowired
    private IFileUploadService fileUploadService;

    @RequestMapping("/pic/upload")
    @ResponseBody
    public TtResult uploda(MultipartFile uploadFile) throws Exception {
        FtpPo ftpPo = new FtpPo();
        ftpPo.setFTP_PORT(FTP_PORT);
        ftpPo.setFTP_USERNAME(FTP_USERNAME);
        ftpPo.setFTPHost(FTPHost);
        ftpPo.setFTPPASSRD(FTPPASSRD);
        ftpPo.setIMAGE_BASE_home(IMAGE_BASE_home);
        ftpPo.setIMAGE_BASE_URL(Image_Base_Url+ TtConstans.filePrefix);
        ftpPo.setFileName(uploadFile.getOriginalFilename());
        ftpPo.setInputStream(uploadFile.getInputStream());

        TtResult result = fileUploadService.uploadFile(ftpPo);
        return result;
    }

}
